<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="layout/includes.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:jsp="http://java.sun.com/JSP/Page">
<head>
  <META http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>stripes-gen</title>
  <link rel="stylesheet" type="text/css" href="css/default.css"/>
  <script type="text/javascript" src="js/tools.js"></script>
</head>
<body>

<#include "../auxftl/constants.ftl">
<#include "../auxftl/outpututils.ftl">
<#include "../auxftl/inpututils.ftl">
<#assign propertyList = createPropertyList() />

<%-- Load resource bundle --%>
<fmt:setBundle basename="messages" var="msgs"/>

<%-- Content --%>
<div id="content">

  <%-- Search form and result list --%>
  <stripes:form beanclass="${controllerPackage}.${entityName}PickerList" focus="">

    <%-- If there is no action bean, from which will be resultset taken, create new --%>
    <c:if test="${'$'}{empty actionBean}">
      <stripes:useActionBean var="actionBean" beanclass="${controllerPackage}.${entityName}PickerList"/>
    </c:if>

    <%-- If result list is not empty, print it --%>
    <c:choose>
      <c:when test="${'$'}{! empty actionBean.resultList}">
        <table>
          <tr class="rowHead">
            <@renderResultHeaderCells controllerPackage=controllerPackage entityName=entityName picker=true/>
            <th></th>
          </tr>
          <tr class="rowFilter">
            <@renderStringFilterCells controllerPackage=controllerPackage entityName=entityName picker=true/>
            <td>
              <stripes:submit name="doFilter"><fmt:message bundle="${'$'}{msgs}" key="custom.global.button.search"/></stripes:submit>
            </td>
          </tr>
          <c:forEach items="${'$'}{actionBean.resultList}" var="i" varStatus="rowstat">
            <tr onclick="javascript:selectTableRow('${getPickerName(entityName)?uncap_first}','${'$'}{i.${getPickerIdentifierName(entityName)}}')" name="${'$'}{rowstat.count mod 2 == 0 ? "tableItemOdd" : "tableItemEven"}" id="${'$'}{i.${getPickerIdentifierName(entityName)}}" class="${'$'}{rowstat.count mod 2 == 0 ? "rowOdd" : "rowEven"}">
              <@renderResultCells rowIteratorName="i" picker=true/>
              <td>
                <input type="button" onclick="javascript:selectTableRow('${getPickerName(entityName)?uncap_first}','${'$'}{i.${getPickerIdentifierName(entityName)}}')" value="<fmt:message bundle="${'$'}{msgs}" key="custom.global.label.select"/>"/>
              </td>
            </tr>
          </c:forEach>
        </table>
      </c:when>
      <c:otherwise>
        <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.emptySearch"/>
      </c:otherwise>
    </c:choose>

    <%-- Paging --%>
    <c:if test="${'$'}{! empty actionBean.resultList}">
      <div class="pagination">
        <span class="paginationleft">
          <c:choose>
            <c:when test="${'$'}{actionBean.prevPageExists}">
              <stripes:link beanclass="${controllerPackage}.${entityName}PickerList" event="doFilter">
                <stripes:param name="firstResult" value="0"/>
                <@renderLinkFilterParams componentName=componentName/>
                <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.firstPage"/>
              </stripes:link>
            </c:when>
            <c:otherwise>
              <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.firstPage"/>
            </c:otherwise>
          </c:choose>
          <c:out value="|"/>
          <c:choose>
            <c:when test="${'$'}{actionBean.prevPageExists}">
              <stripes:link beanclass="${controllerPackage}.${entityName}PickerList" event="doFilter">
                <stripes:param name="firstResult" value="${'$'}{actionBean.prevFirstResult}"/>
                <@renderLinkFilterParams componentName=componentName/>
                <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.previousPage"/>
              </stripes:link>
            </c:when>
            <c:otherwise>
              <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.previousPage"/>
            </c:otherwise>
          </c:choose>
        </span>
        <span class="paginationright">
          <c:choose>
            <c:when test="${'$'}{actionBean.nextPageExists}">
              <stripes:link beanclass="${controllerPackage}.${entityName}PickerList" event="doFilter">
                <stripes:param name="firstResult" value="${'$'}{actionBean.nextFirstResult}"/>
                <@renderLinkFilterParams componentName=componentName/>
                <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.nextPage"/>
              </stripes:link>
            </c:when>
            <c:otherwise>
              <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.nextPage"/>
            </c:otherwise>
          </c:choose>
          <c:out value="|"/>
          <c:choose>
            <c:when test="${'$'}{actionBean.nextPageExists}">
              <stripes:link beanclass="${controllerPackage}.${entityName}PickerList" event="doFilter">
                <stripes:param name="firstResult" value="${'$'}{actionBean.lastFirstResult}"/>
                <@renderLinkFilterParams componentName=componentName/>
                <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.lastPage"/>
              </stripes:link>
            </c:when>
            <c:otherwise>
              <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.lastPage"/>
            </c:otherwise>
          </c:choose>
        </span>
      </div>
    </c:if>
  </stripes:form>
</div>

<%
  if (request.getParameter("SelectedId") != null) {
    out.print("<script>");
    out.print("window.onload=selectTableRow('${getPickerName(entityName)?uncap_first}'," + request.getParameter("SelectedId") + ")");
    out.print("</script>");
  }
%>

</body>
</html>
